
$(function(){
    let $window=$(window);
    let lazyImgs = $.each($('img[src-real]').get(),function(i){
        return $(i);
    })

    let onScroll = function(){
        let wtop=$window.scrollTop;
        if(lazyImgs.length > 0){
            let wheight = $window.outerHeight();
            let loadedIndex = []
            $.each(lazyImgs,function(index,$i){
                console.log($i.offset().top);
                if($i.offset().top < wheight+wtop){
                    $i.attr('src',$i.attr('src-real'));
                    loadedIndex.unshift(index);
                }   
            })
            $.each(loadedIndex,function(index){
                lazyImgs.splice(index,1);
            })
        }
    }
    onScroll();
    $window.scroll(onScroll)
})




























